#ifndef _LABOR_TEXTUREMANAGER_H_
#define _LABOR_TEXTUREMANAGER_H_
#include <vector>
#include "../LaborCoreDef.h"
#include "../Common/LaborHashString.h"
#include "LaborTexture.h"
#include "../LaborCoreDef.h"

#include "../Common/LaborFileOperate.h"
#include "../Common/LaborResourceManager.h"
NAMESPACE_LABOR3D_BEGIN
class  LABORCORE_API  xBaseTextureLoader;

inline bool operator == (const xTextureName& lhv , const xTextureName& rhv)
{
	return lStringHash(lhv.m_Name.c_str() )  == lStringHash(rhv.m_Name.c_str() );
}

inline bool operator < (const xTextureName& lhv , const xTextureName& rhv)
{
	return lStringHash(lhv.m_Name.c_str() )  < lStringHash(rhv.m_Name.c_str() );
}

inline size_t hash_value(const xTextureName& _Keyval)
{
	return ( lStringHash(_Keyval.m_Name.c_str() ));
}


typedef TResHandle      <ILaborTexture , xTextureName , xBaseTextureLoader> HBaseTexture;
typedef TLRUPolicyResMgr<ILaborTexture , xTextureName , xBaseTextureLoader> LaborBaseTextureMgr;

class  LABORCORE_API  xBaseTextureLoader : public xResPathManager
{
	ILRenderSystem*          m_pRenderSys;
public:	
	ILRenderSystem*        renderSys(){return m_pRenderSys ;}
	void                            setRenderSys(ILRenderSystem* pRenderSys) { m_pRenderSys = pRenderSys; }
	HBaseTexture             load(const xTextureName& texName , bool bLoadImm  , bool arg);
	HBaseTexture             loadTexture(const wchar_t* texName, bool bLoadImm  , bool arg);
	//HBaseTexture             loadTexture(const wchar_t* texName , xTextureInitDesc& initDesc , eResourceType type = RESOURCE_TEXTURE2D ) ;
    static LaborBaseTextureMgr*  createInstance(ILRenderSystem* pRenderSys, const wchar_t* _name);   
	void                     setThis(LaborBaseTextureMgr* pThis){m_pThis = pThis; }
protected:
	virtual unsigned int _getResSize(ILaborTexture* pRes);
	virtual bool         _isResLoaded(ILaborTexture* pRes);
	virtual bool         _preLoadResource(const xTextureName& strResName   , ILaborTexture* & pRes , int& ResSize, unsigned int arg)  { return true ; }
	virtual bool         _postLoadResource(const xTextureName& strResName   , ILaborTexture* & pRes , int& ResSize, unsigned int arg) { return true ; }
	virtual bool         _loadResource(const xTextureName& strResName   , ILaborTexture* & pRes , int& ResSize, unsigned int arg);
	virtual bool         _unloadResource(const xTextureName& strResName , ILaborTexture* & pRes , unsigned int& TotalResSize);
	virtual void         _deleteResource(const xTextureName& strResName , ILaborTexture* pRes);
protected:
    xBaseTextureLoader();
	virtual bool    _loadTexture( const xTextureName& _texName  , ILaborTexture*& pTexture , int& ResSize , unsigned int arg);
	ILaborTexture*   _loadTexture( const xTextureName& _texName , const wchar_t* fileName ,unsigned char* buf , int bufLen , unsigned int arg);
 
    LaborBaseTextureMgr*     m_pThis;
    
};

NAMESPACE_LABOR3D_END
#endif
